﻿using System.Windows;
using MachineVision.Core.CircleMeasure;
using MachineVision.Core.OCR;
using MachineVision.Core.TemplateMatch;
using MachineVision.Core.TemplateMatch.LocalDeformable;
using MachineVision.Core.TemplateMatch.NccModel;
using MachineVision.Core.TemplateMatch.ShapeModel;
using MachineVision.Defect;
using MachineVision.ObjectMeasure;
using MachineVision.Ocr;
using MachineVision.Services;
using MachineVision.Shared.Extensions;
using MachineVision.TemplateMatch;
using MachineVision.TemplateMatch.ViewModels;
using MachineVision.TemplateMatch.Views;
using MachineVision.ViewModels;
using MachineVision.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using Prism.Unity;

namespace MachineVision
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //注入mapper
            containerRegistry.RegisterSingleton<IAppMapper, AppMapper>();

            containerRegistry.RegisterForNavigation<MainView, MainViewModel>();
            containerRegistry.RegisterForNavigation<DashboardView, DashboardViewModel>();
            containerRegistry.RegisterForNavigation<SettingView, SettingViewModel>();
            containerRegistry.RegisterForNavigation<DrawShapeView, DrawShapeViewModel>();

            containerRegistry.Register<QrCodeService>();
            containerRegistry.Register<BarCodeService>();
            containerRegistry.Register<CircleMeasureService>();
            //注册模板匹配
            containerRegistry.Register<ITemplateMatchService, ShapeModelService>(
                nameof(TemplateMatchType.ShapeModel)
            );
            containerRegistry.Register<ITemplateMatchService, NccModelService>(
                nameof(TemplateMatchType.NccModel)
            );
            containerRegistry.Register<ITemplateMatchService, LocalDeformableService>(
                nameof(TemplateMatchType.LocalDeformable)
            );
            containerRegistry.RegisterSingleton<INavigationService, NavigationService>();
        }

        protected override void InitializeShell(Window shell)
        {
            //Windos初始化完成后初始化导航菜单
            if (shell.DataContext is INavigationAware navigationAware)
                navigationAware.OnNavigatedTo(null);
            base.InitializeShell(shell);
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<TemplateMatchModule>();
            moduleCatalog.AddModule<OcrModule>();
            moduleCatalog.AddModule<DefectModule>();
            moduleCatalog.AddModule<ObjectMeasureModule>();
            base.ConfigureModuleCatalog(moduleCatalog);
        }
    }
}
